package com.voicecheck.adapter;

import java.util.List;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.aris.voicechecking.R;
import com.voicecheck.model.HistoryModel;

public class HistoryLessonAdapter extends BaseAdapter {

    private List<HistoryModel> listData;

    public HistoryLessonAdapter(List<HistoryModel> list) {
        listData = list;
    }

    @Override
    public int getCount() {
        return listData.size();
    }

    @Override
    public Object getItem(int arg0) {
        return listData.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(
                    R.layout.item_lesson_day, parent, false);

            holder = new ViewHolder();
            holder.date = (TextView) convertView
                    .findViewById(R.id.lesson_title);
            holder.sometext = (TextView) convertView
                    .findViewById(R.id.question_number);

            holder.date.setTextColor(Color.BLACK);
            holder.sometext.setTextColor(Color.BLACK);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        HistoryModel model = (HistoryModel) getItem(position);

        holder.date.setText(model.getDate());
        holder.sometext
        .setText(model.getPass_count()
                + "/"
                + model.getQuestion_count()
                + " "
                + parent.getContext().getResources()
                .getString(R.string.question));
        holder.sometext.setTextColor(Color.BLACK);

        return convertView;
    }

    static class ViewHolder {
        TextView date;
        TextView sometext;
    }

}
